
#include "PyProError.h"
#include "ProToolkitErrors.h"

PyObject *
PyProError_str(PyProError* self,PyObject *args)
{

	const char* str(0);
	ProError inputT;
	if (! PyArg_ParseTuple(self->args, "i", &inputT)) 
		return NULL; 
	switch(inputT)
	{
	case	PRO_TK_NO_ERROR	:	 str 	=	"PRO_TK_NO_ERROR"	;	 break;
	case	PRO_TK_GENERAL_ERROR	:	 str 	=	"PRO_TK_GENERAL_ERROR"	;	 break;
	case	PRO_TK_BAD_INPUTS	:	 str 	=	"PRO_TK_BAD_INPUTS"	;	 break;
	case	PRO_TK_USER_ABORT	:	 str 	=	"PRO_TK_USER_ABORT"	;	 break;
	case	PRO_TK_E_NOT_FOUND	:	 str 	=	"PRO_TK_E_NOT_FOUND"	;	 break;
	case	PRO_TK_E_FOUND	:	 str 	=	"PRO_TK_E_FOUND"	;	 break;
	case	PRO_TK_LINE_TOO_LONG	:	 str 	=	"PRO_TK_LINE_TOO_LONG"	;	 break;
	case	PRO_TK_CONTINUE	:	 str 	=	"PRO_TK_CONTINUE"	;	 break;
	case	PRO_TK_BAD_CONTEXT	:	 str 	=	"PRO_TK_BAD_CONTEXT"	;	 break;
	case	PRO_TK_NOT_IMPLEMENTED	:	 str 	=	"PRO_TK_NOT_IMPLEMENTED"	;	 break;
	case	PRO_TK_OUT_OF_MEMORY	:	 str 	=	"PRO_TK_OUT_OF_MEMORY"	;	 break;
	case	PRO_TK_COMM_ERROR	:	 str 	=	"PRO_TK_COMM_ERROR"	;	 break;
	case	PRO_TK_NO_CHANGE	:	 str 	=	"PRO_TK_NO_CHANGE"	;	 break;
	case	PRO_TK_SUPP_PARENTS	:	 str 	=	"PRO_TK_SUPP_PARENTS"	;	 break;
	case	PRO_TK_PICK_ABOVE	:	 str 	=	"PRO_TK_PICK_ABOVE"	;	 break;
	case	PRO_TK_INVALID_DIR	:	 str 	=	"PRO_TK_INVALID_DIR"	;	 break;
	case	PRO_TK_INVALID_FILE	:	 str 	=	"PRO_TK_INVALID_FILE"	;	 break;
	case	PRO_TK_CANT_WRITE	:	 str 	=	"PRO_TK_CANT_WRITE"	;	 break;
	case	PRO_TK_INVALID_TYPE	:	 str 	=	"PRO_TK_INVALID_TYPE"	;	 break;
	case	PRO_TK_INVALID_PTR	:	 str 	=	"PRO_TK_INVALID_PTR"	;	 break;
	case	PRO_TK_UNAV_SEC	:	 str 	=	"PRO_TK_UNAV_SEC"	;	 break;
	case	PRO_TK_INVALID_MATRIX	:	 str 	=	"PRO_TK_INVALID_MATRIX"	;	 break;
	case	PRO_TK_INVALID_NAME	:	 str 	=	"PRO_TK_INVALID_NAME"	;	 break;
	case	PRO_TK_NOT_EXIST	:	 str 	=	"PRO_TK_NOT_EXIST"	;	 break;
	case	PRO_TK_CANT_OPEN	:	 str 	=	"PRO_TK_CANT_OPEN"	;	 break;
	case	PRO_TK_ABORT	:	 str 	=	"PRO_TK_ABORT"	;	 break;
	case	PRO_TK_NOT_VALID	:	 str 	=	"PRO_TK_NOT_VALID"	;	 break;
	case	PRO_TK_INVALID_ITEM	:	 str 	=	"PRO_TK_INVALID_ITEM"	;	 break;
	case	PRO_TK_MSG_NOT_FOUND	:	 str 	=	"PRO_TK_MSG_NOT_FOUND"	;	 break;
	case	PRO_TK_MSG_NO_TRANS	:	 str 	=	"PRO_TK_MSG_NO_TRANS"	;	 break;
	case	PRO_TK_MSG_FMT_ERROR	:	 str 	=	"PRO_TK_MSG_FMT_ERROR"	;	 break;
	case	PRO_TK_MSG_USER_QUIT	:	 str 	=	"PRO_TK_MSG_USER_QUIT"	;	 break;
	case	PRO_TK_MSG_TOO_LONG	:	 str 	=	"PRO_TK_MSG_TOO_LONG"	;	 break;
	case	PRO_TK_CANT_ACCESS	:	 str 	=	"PRO_TK_CANT_ACCESS"	;	 break;
	case	PRO_TK_OBSOLETE_FUNC	:	 str 	=	"PRO_TK_OBSOLETE_FUNC"	;	 break;
	case	PRO_TK_NO_COORD_SYSTEM	:	 str 	=	"PRO_TK_NO_COORD_SYSTEM"	;	 break;
	case	PRO_TK_E_AMBIGUOUS	:	 str 	=	"PRO_TK_E_AMBIGUOUS"	;	 break;
	case	PRO_TK_E_DEADLOCK	:	 str 	=	"PRO_TK_E_DEADLOCK"	;	 break;
	case	PRO_TK_E_BUSY	:	 str 	=	"PRO_TK_E_BUSY"	;	 break;
	case	PRO_TK_E_IN_USE	:	 str 	=	"PRO_TK_E_IN_USE"	;	 break;
	case	PRO_TK_NO_LICENSE	:	 str 	=	"PRO_TK_NO_LICENSE"	;	 break;
	case	PRO_TK_BSPL_UNSUITABLE_DEGREE	:	 str 	=	"PRO_TK_BSPL_UNSUITABLE_DEGREE"	;	 break;
	case	PRO_TK_BSPL_NON_STD_END_KNOTS	:	 str 	=	"PRO_TK_BSPL_NON_STD_END_KNOTS"	;	 break;
	case	PRO_TK_BSPL_MULTI_INNER_KNOTS	:	 str 	=	"PRO_TK_BSPL_MULTI_INNER_KNOTS"	;	 break;
	case	PRO_TK_BAD_SRF_CRV	:	 str 	=	"PRO_TK_BAD_SRF_CRV"	;	 break;
	case	PRO_TK_EMPTY	:	 str 	=	"PRO_TK_EMPTY"	;	 break;
	case	PRO_TK_BAD_DIM_ATTACH	:	 str 	=	"PRO_TK_BAD_DIM_ATTACH"	;	 break;
	case	PRO_TK_NOT_DISPLAYED	:	 str 	=	"PRO_TK_NOT_DISPLAYED"	;	 break;
	case	PRO_TK_CANT_MODIFY	:	 str 	=	"PRO_TK_CANT_MODIFY"	;	 break;
	case	PRO_TK_CHECKOUT_CONFLICT	:	 str 	=	"PRO_TK_CHECKOUT_CONFLICT"	;	 break;
	case	PRO_TK_CRE_VIEW_BAD_SHEET	:	 str 	=	"PRO_TK_CRE_VIEW_BAD_SHEET"	;	 break;
	case	PRO_TK_CRE_VIEW_BAD_MODEL	:	 str 	=	"PRO_TK_CRE_VIEW_BAD_MODEL"	;	 break;
	case	PRO_TK_CRE_VIEW_BAD_PARENT	:	 str 	=	"PRO_TK_CRE_VIEW_BAD_PARENT"	;	 break;
	case	PRO_TK_CRE_VIEW_BAD_TYPE	:	 str 	=	"PRO_TK_CRE_VIEW_BAD_TYPE"	;	 break;
	case	PRO_TK_CRE_VIEW_BAD_EXPLODE	:	 str 	=	"PRO_TK_CRE_VIEW_BAD_EXPLODE"	;	 break;
	case	PRO_TK_UNATTACHED_FEATS	:	 str 	=	"PRO_TK_UNATTACHED_FEATS"	;	 break;
	case	PRO_TK_REGEN_AGAIN	:	 str 	=	"PRO_TK_REGEN_AGAIN"	;	 break;
	case	PRO_TK_DWGCREATE_ERRORS	:	 str 	=	"PRO_TK_DWGCREATE_ERRORS"	;	 break;
	case	PRO_TK_UNSUPPORTED	:	 str 	=	"PRO_TK_UNSUPPORTED"	;	 break;
	case	PRO_TK_NO_PERMISSION	:	 str 	=	"PRO_TK_NO_PERMISSION"	;	 break;
	case	PRO_TK_AUTHENTICATION_FAILURE	:	 str 	=	"PRO_TK_AUTHENTICATION_FAILURE"	;	 break;
	case	PRO_TK_OUTDATED	:	 str 	=	"PRO_TK_OUTDATED"	;	 break;
	case	PRO_TK_INCOMPLETE	:	 str 	=	"PRO_TK_INCOMPLETE"	;	 break;
	case	PRO_TK_CHECK_OMITTED	:	 str 	=	"PRO_TK_CHECK_OMITTED"	;	 break;
	//case	PRO_TK_MAX_LIMIT_REACHED	:	 str 	=	"PRO_TK_MAX_LIMIT_REACHED"	;	 break;
	//case	PRO_TK_OUT_OF_RANGE	:	 str 	=	"PRO_TK_OUT_OF_RANGE"	;	 break;
	case	PRO_TK_APP_TOO_OLD	:	 str 	=	"PRO_TK_APP_TOO_OLD"	;	 break;
	case	PRO_TK_APP_BAD_DATAPATH	:	 str 	=	"PRO_TK_APP_BAD_DATAPATH"	;	 break;
	case	PRO_TK_APP_BAD_ENCODING	:	 str 	=	"PRO_TK_APP_BAD_ENCODING"	;	 break;
	case	PRO_TK_APP_NO_LICENSE	:	 str 	=	"PRO_TK_APP_NO_LICENSE"	;	 break;
	case	PRO_TK_APP_XS_CALLBACKS	:	 str 	=	"PRO_TK_APP_XS_CALLBACKS"	;	 break;
	case	PRO_TK_APP_STARTUP_FAIL	:	 str 	=	"PRO_TK_APP_STARTUP_FAIL"	;	 break;
	case	PRO_TK_APP_INIT_FAIL	:	 str 	=	"PRO_TK_APP_INIT_FAIL"	;	 break;
	case	PRO_TK_APP_VERSION_MISMATCH	:	 str 	=	"PRO_TK_APP_VERSION_MISMATCH"	;	 break;
	case	PRO_TK_APP_COMM_FAILURE	:	 str 	=	"PRO_TK_APP_COMM_FAILURE"	;	 break;
	case	PRO_TK_APP_NEW_VERSION	:	 str 	=	"PRO_TK_APP_NEW_VERSION"	;	 break;
	case	PRO_TK_APP_UNLOCK	:	 str 	=	"PRO_TK_APP_UNLOCK"	;	 break;


	default:
		return NULL;
	}
	return  Py_BuildValue("s",str);
}


static PyMethodDef ProError_methods[] = {
	//{"str", (PyCFunction)PyProError_str, METH_VARARGS|METH_STATIC,"Return the ErrorString"},

	{NULL}  /* Sentinel */
};

static int
PyProError_traverse(PyProError *self, visitproc visit, void *arg)
{
    Py_VISIT(self->dict);
    Py_VISIT(self->args);
    Py_VISIT(self->traceback);
    Py_VISIT(self->cause);
    Py_VISIT(self->context);
    return 0;
}

static int
PyProError_clear(PyProError *self)
{
	Py_CLEAR(self->dict);
	Py_CLEAR(self->args);
	Py_CLEAR(self->traceback);
	Py_CLEAR(self->cause);
	Py_CLEAR(self->context);
	return 0;
}

static void
PyProError_dealloc(PyProError *self)
{
	_PyObject_GC_UNTRACK(self);
	PyProError_clear(self);
	Py_TYPE(self)->tp_free((PyObject *)self);
}

static PyObject *
PyProError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	PyProError *self;

	self = (PyProError *)type->tp_alloc(type, 0);
	if (!self)
		return NULL;
	/* the dict is created on the fly in PyObject_GenericSetAttr */
	self->dict = NULL;
	self->traceback = self->cause = self->context = NULL;

	Py_INCREF(args);
	self->args = args;
	if (!self->args) {
		Py_DECREF(self);
		return NULL;
	}

	return (PyObject *)self;
}

static int
PyProError_init(PyProError *self, PyObject *args, PyObject *kwds)
{
    if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
        return -1;

    Py_DECREF(self->args);
    self->args = args;
    Py_INCREF(self->args);

    return 0;
}
	 

PyTypeObject pyProErrorType = {
	PyVarObject_HEAD_INIT(NULL, 0)
	"ProError",             /* tp_name */
	sizeof(PyProError),			/* tp_basicsize */
	0,                         /* tp_itemsize */
	(destructor)PyProError_dealloc,                         /* tp_dealloc */
	0,                         /* tp_print */
	0,                         /* tp_getattr */
	0,                         /* tp_setattr */
	0,                         /* tp_reserved */
	0,                         /* tp_repr */
	0,                         /* tp_as_number */
	0,                         /* tp_as_sequence */
	0,                         /* tp_as_mapping */
	0,                         /* tp_hash  */
	0,                         /* tp_call */
	(reprfunc)PyProError_str,                        /* tp_str */
	0,                         /* tp_getattro */
	0,                         /* tp_setattro */
	0,                         /* tp_as_buffer */
	Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE,        /* tp_flags */
	"ProError objects",           /* tp_doc */
	(traverseproc)PyProError_traverse,		               /* tp_traverse */
	(inquiry)PyProError_clear,		               /* tp_clear */
	0,		               /* tp_richcompare */
	0,		               /* tp_weaklistoffset */
	0,		               /* tp_iter */
	0,		               /* tp_iternext */
	ProError_methods,             /* tp_methods */
	0,             /* tp_members */
	0,                         /* tp_getset */
	(PyTypeObject *)PyExc_BaseException,                         /* tp_base */
	0,                         /* tp_dict */
	0,                         /* tp_descr_get */
	0,                         /* tp_descr_set */
	0,                         /* tp_dictoffset */
	(initproc)PyProError_init,      /* tp_init */
	0,                         /* tp_alloc */
	PyProError_new,                 /* tp_new */
}; 


int PyInit_ProError_Type( PyObject *m )
{

	PyObject * ProErrorDict  = PyDict_New();
	Py_INCREF(ProErrorDict);

	ENUM_DICT(ProErrorDict,	PRO_TK_NO_ERROR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_GENERAL_ERROR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BAD_INPUTS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_USER_ABORT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_NOT_FOUND	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_FOUND	);
	ENUM_DICT(ProErrorDict,	PRO_TK_LINE_TOO_LONG	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CONTINUE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BAD_CONTEXT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NOT_IMPLEMENTED	);
	ENUM_DICT(ProErrorDict,	PRO_TK_OUT_OF_MEMORY	);
	ENUM_DICT(ProErrorDict,	PRO_TK_COMM_ERROR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NO_CHANGE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_SUPP_PARENTS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_PICK_ABOVE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_DIR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_FILE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CANT_WRITE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_TYPE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_PTR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_UNAV_SEC	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_MATRIX	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_NAME	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NOT_EXIST	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CANT_OPEN	);
	ENUM_DICT(ProErrorDict,	PRO_TK_ABORT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NOT_VALID	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INVALID_ITEM	);
	ENUM_DICT(ProErrorDict,	PRO_TK_MSG_NOT_FOUND	);
	ENUM_DICT(ProErrorDict,	PRO_TK_MSG_NO_TRANS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_MSG_FMT_ERROR	);
	ENUM_DICT(ProErrorDict,	PRO_TK_MSG_USER_QUIT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_MSG_TOO_LONG	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CANT_ACCESS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_OBSOLETE_FUNC	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NO_COORD_SYSTEM	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_AMBIGUOUS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_DEADLOCK	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_BUSY	);
	ENUM_DICT(ProErrorDict,	PRO_TK_E_IN_USE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NO_LICENSE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BSPL_UNSUITABLE_DEGREE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BSPL_NON_STD_END_KNOTS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BSPL_MULTI_INNER_KNOTS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BAD_SRF_CRV	);
	ENUM_DICT(ProErrorDict,	PRO_TK_EMPTY	);
	ENUM_DICT(ProErrorDict,	PRO_TK_BAD_DIM_ATTACH	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NOT_DISPLAYED	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CANT_MODIFY	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CHECKOUT_CONFLICT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CRE_VIEW_BAD_SHEET	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CRE_VIEW_BAD_MODEL	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CRE_VIEW_BAD_PARENT	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CRE_VIEW_BAD_TYPE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CRE_VIEW_BAD_EXPLODE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_UNATTACHED_FEATS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_REGEN_AGAIN	);
	ENUM_DICT(ProErrorDict,	PRO_TK_DWGCREATE_ERRORS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_UNSUPPORTED	);
	ENUM_DICT(ProErrorDict,	PRO_TK_NO_PERMISSION	);
	ENUM_DICT(ProErrorDict,	PRO_TK_AUTHENTICATION_FAILURE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_OUTDATED	);
	ENUM_DICT(ProErrorDict,	PRO_TK_INCOMPLETE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_CHECK_OMITTED	);
	//ENUM_DICT(ProErrorDict,	PRO_TK_MAX_LIMIT_REACHED	);
	//ENUM_DICT(ProErrorDict,	PRO_TK_OUT_OF_RANGE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_TOO_OLD	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_BAD_DATAPATH	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_BAD_ENCODING	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_NO_LICENSE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_XS_CALLBACKS	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_STARTUP_FAIL	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_INIT_FAIL	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_VERSION_MISMATCH	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_COMM_FAILURE	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_NEW_VERSION	);
	ENUM_DICT(ProErrorDict,	PRO_TK_APP_UNLOCK	);


	pyProErrorType.tp_dict = ProErrorDict;
	PyType_Ready(&pyProErrorType);
	Py_INCREF(&pyProErrorType);
	return PyModule_AddObject(m, "Mode", (PyObject *)&pyProErrorType);
}

